package main.com.votes.dao;

import main.com.votes.model.Option;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

public class OptionDao extends BaseDAO{

    //    插入选项
    public int addOption(int articleId, String value) {
        String sql = "INSERT INTO optionss VALUES(0,?,?)";
        return super.update(sql, new Object[]{value, articleId});
    }

    @Override
    public Option rowMapper(ResultSet rs) throws SQLException {
        return new Option(
                rs.getInt(1),
                rs.getString(2),
                rs.getInt(3)
        );
    }

    public List<Option> getByArticleId(int articleid) {
        String sql = "select * from optionss where articleid=?";
        return super.selectAll(sql, new Object[]{articleid});
    }
}
